home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / lib / partman / finish.d / 10clear_partitions next >
Encoding:
Text File  |  2009-04-19  |  2.7 KB  |  99 lines

  1. #! /bin/sh
  2. # Remove critical files to ensure we don't end up with a mixed system.
  3.  
  4. . /lib/partman/lib/base.sh
  5.  
  6. failed () {
  7.     db_progress STOP
  8.     db_input critical partman-target/clear_partitions_failed || true
  9.     db_go || true
  10.     exit 1
  11. }
  12. count=0
  13. partitions=$(
  14. for dev in $DEVICES/*; do
  15.     [ -d "$dev" ] || continue
  16.     cd $dev
  17.     open_dialog PARTITIONS
  18.     while { read_line num id size type fs path name; [ "$id" ]; }; do
  19.         [ -f "$id/method" ] || continue
  20.         [ -f "$id/use_filesystem" ] || continue
  21.         [ -f "$id/mountpoint" ] || continue
  22.         [ "$fs" != free ] || continue
  23.         [ -f "$id/format" ] && continue
  24.         [ -f "$id/formatted" ] && continue
  25.         count=$(($count + 1))
  26.         mp="$(cat "$id/mountpoint")"
  27.         echo "$mp,$path"
  28.     done
  29.     close_dialog
  30. done | sort
  31. )
  32.  
  33. [ -n "$partitions" ] || exit 0
  34.  
  35. echo "Considering $partitions." | tr '\n' ' ' | logger -t clear_partitions
  36.  
  37. tmp="/mnt/tmpmount"
  38. mkdir -p "$tmp"
  39. template=partman-target/clear_partitions_progress
  40. db_progress START 0 $count ubiquity/install/title
  41. db_progress INFO $template
  42. to_delete=""
  43. for part in $partitions; do
  44.     mp="${part%,*}"
  45.     path="${part#*,}"
  46.     if [ "$mp" = "/" ]; then
  47.         mount $path $tmp || failed
  48.         for x in bin dev etc lib lib32 lib64 proc sbin usr var sys; do
  49.             [ -e "$tmp/$x" ] && (rm -rf "$tmp/$x" &&
  50.             logger -t clear_partitions "Removing $x from / ($path)." ||
  51.             failed)
  52.         done
  53.         for x in $tmp/initrd* $tmp/vmlinuz*; do
  54.             [ -e "$x" ] && (rm -rf "$x" || failed)
  55.         done
  56.         
  57.         # /home could be a symlink.
  58.         [ -f "$tmp/home" ] && (rm "$tmp/home" || failed)
  59.  
  60.         # / could have the wrong owner.
  61.         chown root:root $tmp
  62.         
  63.         # Preserve the UID, if possible.
  64.         db_get passwd/username || true
  65.         username="$RET"
  66.         if [ -n "$username" ] && [ -d "$tmp/home/$username" ]; then
  67.             db_set passwd/user-uid "$(stat -c %u "$tmp/home/$username")" || true
  68.             db_set passwd/user-gid "$(stat -c %g "$tmp/home/$username")" || true
  69.         fi
  70.         umount $tmp
  71.     elif [ "$mp" = "/home" ]; then
  72.         mount $path $tmp || failed
  73.         # Preserve the UID, if possible.
  74.         db_get passwd/username || true
  75.         username="$RET"
  76.         if [ -n "$username" ] && [ -d "$tmp/$username" ]; then
  77.             db_set passwd/user-uid "$(stat -c %u "$tmp/$username")" || true
  78.             db_set passwd/user-gid "$(stat -c %g "$tmp/$username")" || true
  79.         fi
  80.         umount $tmp
  81.     elif echo "$mp" | egrep -q "^/usr/local" || echo "$mp" | egrep -q "^/var/local"; then
  82.         logger -t clear_partitions "Skipping $mp ($path)."
  83.         continue
  84.     else
  85.         for x in bin dev etc lib lib32 lib64 proc sbin usr var sys; do
  86.             if echo "$mp" | egrep -q "^/$x(\$|/)"; then
  87.                 mount $path $tmp || failed
  88.                 logger -t clear_partitions "Removing everything from $mp ($path)."
  89.                 rm -rf $tmp/* || failed
  90.                 umount $tmp
  91.                 break
  92.             fi
  93.         done
  94.     fi
  95.     db_progress STEP 1
  96. done
  97. db_progress STOP
  98. rmdir $tmp
  99.